/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Main.AppConstants;
import java.awt.*;
import java.io.Serializable;
import javax.swing.ImageIcon;

/**
 *
 * @author sa11
 */
public class DiscIcon extends ImageIcon implements Serializable{

    private Image image = new ImageIcon(getClass().getClassLoader().getResource(AppConstants.IMAGE_DISC)).getImage();
    private Color color;
    private double scale = 1;

    public DiscIcon(Color color) {
        this.color = color;
        setImage(image);
    }

    public DiscIcon() {
        this(Color.RED);
    }

    /**
     * Optional constructor with scale parameter, to scale the ImageIcon size
     */
    public DiscIcon(Color color, double scale) {
        this.color = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        this.scale = scale;
        setImage(image);
    }

    /**
     * Sets DiscIcon scale
     */
    public void setScale(double scale) {
        this.scale = scale;
    }

    /**
     * Returns the scale
     */
    public double getScale() {
        return scale;
    }

    /**
     * Set color for the disc object
     */
    public void setColor(Color color) {
        this.color = color;
    }

    /**
     * Return the disc object's color
     */
    public Color getColor() {
        return color;
    }

    @Override
    public int getIconHeight() {
        return (int) ((double) image.getHeight(null) * scale);
    }

    @Override
    public int getIconWidth() {
        return (int) ((double) image.getWidth(null) * scale);
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        Graphics2D g2D = (Graphics2D) g;                // use G2D so we can use scale() and setRenderingHints()
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);

        g2D.scale(scale, scale);                                // Scale the image
        g2D.drawImage(getImage(), x, y, c);     // Drawin image so that setXORmode() doesn't invert the image color on dark bg:
        g2D.setXORMode(color);                          // Blend the color:
        g2D.drawImage(getImage(), x, y, c);     // Draw image again
    }
}
